package com.yan.file;

import java.io.File;
import java.io.IOException;

public class FileDemo6 {
    public static void main(String[] args) throws IOException {
        File scoresFile = new File("day05_code/src/com/yan");
        File destFile = new File("day05_code/src/com/yan2");
        copy(scoresFile , destFile);
    }

    public static void copy(File scoresFile , File destFile) throws IOException {
        // 判断
        if(scoresFile.exists() && scoresFile.isDirectory()&& destFile.exists() && destFile.isDirectory()){
            File[] files = scoresFile.listFiles();
            for (File ziFile : files) {
                File newFile = new File(destFile, ziFile.getName());
                if(ziFile.isFile()){
                    if(!newFile.exists()){
                        newFile.createNewFile();
                    }
                }else{
                    if(!newFile.exists()){
                        newFile.mkdirs();
                    }
                    File newFiles = new File(destFile, newFile.getName());
                    copy(ziFile , newFiles);
                }
            }
        }
    }

}
